package javagprssrv.COMMAction;

import javagprssrv.JGS_Param;
import javagprssrv.StructClass.structCOMMTask;
import javagprssrv.StructClass.structCOMMTerm;

public class TrdCOMMTermDaemon extends java.lang.Thread
{
    public javagprssrv.StructClass.structCOMMTerm COMMTerm;
    public javagprssrv.StructClass.structCOMMTask COMMTask;
    
    public TrdCOMMTermDaemon(final javagprssrv.StructClass.structCOMMTerm _COMMTerm) {
        super("TrdCOMMTermDaemon");
        this.COMMTerm = new javagprssrv.StructClass.structCOMMTerm();
        this.COMMTask = new javagprssrv.StructClass.structCOMMTask();
        this.COMMTerm = _COMMTerm;
    }
    
    @java.lang.Override
    public void run() {
        while (true) {
            synchronized (javagprssrv.JGS_Param.UnDoneCOMMTasks) {
                if (javagprssrv.JGS_Param.UnDoneCOMMTasks.size() > 1000) {
                    javagprssrv.JGS_Param.UnDoneCOMMTasks.clear();
                }
            }
            if (!this.COMMTerm.isFree) {
                try {
                    java.lang.Thread.sleep(50L);
                }
                catch (java.lang.Exception e) {}
            }
            else {
                boolean isFindUndoneCOMMTask = false;
                synchronized (javagprssrv.JGS_Param.UnDoneCOMMTasks) {
                    if (javagprssrv.JGS_Param.UnDoneCOMMTasks.size() > 0) {
                        this.COMMTask = ((structCOMMTask)javagprssrv.JGS_Param.UnDoneCOMMTasks.remove(0));
                        isFindUndoneCOMMTask = true;
                    }
                }
                if (!isFindUndoneCOMMTask) {
                    try {
                        java.lang.Thread.sleep(50L);
                    }
                    catch (java.lang.Exception e2) {}
                }
                else {
                    if (this.COMMTask.TaskType == 0) {
                        this.COMM_Dial(this.COMMTask.TelNo, javagprssrv.JGS_Param._DialSeconds);
                    }
                    if (this.COMMTask.TaskType == 1) {}
                }
            }
        }
    }
    
    public void COMM_SetReturnAsString() {
        this.COMMTerm.SB.WritePort("atv1\r\n");
    }
    
    public void COMM_SetReturnAsInt() {
        this.COMMTerm.SB.WritePort("atv0\r\n");
    }
    
    public void COMM_Dial(final java.lang.String TelNo, final int DialDelaySeconds) {
        this.COMMTerm.SB.WritePort("atd" + TelNo + ";\r\n");
        try {
            java.lang.Thread.sleep(DialDelaySeconds * 1000);
        }
        catch (java.lang.Exception ex) {}
        this.COMMTerm.SB.WritePort("ath\r\n");
        try {
            java.lang.Thread.sleep(500L);
        }
        catch (java.lang.Exception ex2) {}
    }
    
    public void COMM_SendMessage(final java.lang.String TelNo, final java.lang.String SMSText) {
    }
    
    public void COMM_GPRS_OnLine(final java.lang.String GPRSOnLineDialTelNo) {
    }
    
    public void COMM_GPRS_Write(final java.lang.String RemoteIP, final int RemotePort, final java.lang.String strData) {
    }
}
